package com.lnlyj.imagetext.demo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.lnlyj.imagtext.ImageTextView;

import java.io.IOException;
import java.io.InputStream;

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ImageTextView textView = findViewById(R.id.tv);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    InputStream is = getAssets().open("demo.txt");
                    final StringBuilder sb = new StringBuilder();
                    int length = 0;
                    byte[] bytes = new byte[1024];
                    while ((length = is.read(bytes, 0, bytes.length)) != -1) {
                        sb.append(new String(bytes, 0, length));
                    }
                    textView.post(new Runnable() {
                        @Override
                        public void run() {
//                            sb.append("从工厂Res目录加载的图片：");
//                            sb.append("<img src=\""+R.mipmap.ic_launcher+"\">");
//                            Log.d("XXXXX", "run: " + textView.getLineCount());
                            textView.setImageSource(ImageTextView.IMAGE_SOURCE_SDCARD);
                            textView.setPath("/sdcard/");
                            textView.setImageText(sb.toString().replace("\\n", "\n"));
                            textView.post(new Runnable() {
                                @Override
                                public void run() {
                                }
                            });


//                            textView.setImageSource(ImageTextView.IMAGE_SOURCE_RESOURCE);
//                            textView.setImageText(sb.toString().replace("\\n", "\n"));
//                            textView.setPath("/sdcard/");
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();


    }
}
